// pages/myreserveplan/myreserveplan.js
import { ajax, src, util } from "../../utils/util.js";

const app = getApp()
let isIphoneX = app.globalData.isIphoneX;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    uqid: '',
    pid:'',
    myplan:[],
    userinfo:[],
    isIphoneX: isIphoneX,
    showpayandre:false,
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var pid = options.ppid
    console.log(pid)
    if(!pid){

      pid = wx.getStorageSync("pid");
    }

    wx.setStorageSync("pid", pid)

    var uqid = wx.getStorageSync("uqid");
    
    this.setData({
      uqid: uqid
    });

    this.setData({
      pid: pid
    });

    this.getGenPlan();
    this.getInfo(uqid);    
  },
  //获取个人信息
  getInfo: function (uqid) {
    ajax("/api/index/user_info", {
      data: {
        uqid: uqid,
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
    }, res => {
      // console.log(res);
      if (res.error == 0) {
        this.setData({
          userinfo: res.data,
        });
      }
    })
  },
  //获取康复方案
  getGenPlan:function(){
    ajax("/api/index/generation_plan", {
      data: {
        uqid: this.data.uqid,
        pid: this.data.pid,
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
      method: 'GET'
    }, res => {
      console.log(res);
      if (res.error == 0) {
        this.setData({
          myplan:res.data,
        });
        // 1 - 已下过单 0 - 未下单
        if (res.data.order_status==0){
          this.setData({
            showpayandre: true
          });
        }
      } else if (res.error == 1) {
        wx.showToast({
          title: '您生成的康复方案无效，请重新测评！',
        })
      }
    })
  },
  //康复机构详情
  mechClick: function (e) {
    var id = e.currentTarget.dataset.id;
    // wx.navigateTo({
    //   url: '/pages/mechanismdetails/mechanismdetails?id=' + id,
    // })

    wx.navigateTo({
      url: '../mechanismdetails/mechanismdetails?id=' + id,
    })
  },
  //案例分享
  caseClick: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/case/case?id=' + id,
    })
  },
  //立即预约
  reserveBtn: function () {
    var goods_id = this.data.myplan.goods_id;
    wx.navigateTo({
      url: '/pages/reserveintro/reserveintro?goods_id=' + goods_id,
    })
  },
  recClick:function(){
    // var goods_id = this.data.myplan.goods_id;
    // wx.navigateTo({
    //   url: '/pages/serviceintro/serviceintro?goods_id=' + goods_id,
    // })
    // wx.navigateTo({
    //   url: '/pages/functionalimpairment/functionalimpairment',
    // })

    wx.navigateTo({
      url: '../functionalimpairment/functionalimpairment',
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

 
})